package com.jwsoft.manager.core.integration.addressParse;

import com.jwsoft.manager.common.vo.addressParse.Address;
import lombok.Data;

import java.util.Objects;

@Data
public class AlternativeData {

    public AlternativeData(Address data,
                           AlternativeData parent, int level, String matchValue) {
        this.data = data;
        this.matchValue = matchValue;
        this.parentId = data.getParentId();
        this.level = level;
        this.addressId = data.getAddressId();
        this.areaType=data.getAreaType();
        if (parent != null) {
            this.fullMatchValue = parent.getFullMatchValue() + matchValue;
        } else {
            this.fullMatchValue = matchValue;
        }
    }

    /**
     * 当前级别
     */
    private int level;
    private Address data;
    private AlternativeData parent;
    private Long parentId;
    private String areaType;
    private String matchValue;

    /**
     * 完整的匹配值
     */
    private String fullMatchValue = "";

    private Long addressId;

    @Override
    public boolean equals(Object o) {
        if (this == o){ return true;}
        if (o == null || getClass() != o.getClass()){ return false;}

        AlternativeData that = (AlternativeData) o;

        return Objects.equals(addressId, that.addressId);
    }

    @Override
    public int hashCode() {
        return addressId != null ? addressId.hashCode() : 0;
    }
}
